﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ThridGroup.ERP.DTO;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace ThridGroup.ERP.ProductionSystem
{
    public class EquipmentTypeService : ApplicationService, EquipmentTypeIService
    {
        private readonly IRepository<EquipmentTypeModel, int> _equipmentrepository;
        public EquipmentTypeService(IRepository<EquipmentTypeModel, int> equipmentrepository)
        {
            _equipmentrepository = equipmentrepository;
        }

        public async Task<int> AddEquipmentType(EquipmentTypeDTO equipmentType)
        {
            var list = ObjectMapper.Map<EquipmentTypeDTO, EquipmentTypeModel>(equipmentType);
            var result = await _equipmentrepository.InsertAsync(list);
            return result == null ? 0 : 1;
        }

        public async Task<int> DeleteWorkmanship(int equipmentTypeId)
        {
            var Del = _equipmentrepository.DeleteAsync(c => c.Id == equipmentTypeId);
            return Del == null ? 0 : 1;
        }

        public async Task<EquipmentTypeDTO> FanEquipmentType(int equipmentTypeId)
        {
            var list = await _equipmentrepository.FindAsync(c=>c.Id==equipmentTypeId);
            var result = ObjectMapper.Map<EquipmentTypeModel, EquipmentTypeDTO>(list);
            return result;
        }

        public async Task<List<EquipmentTypeDTO>> GetEquipmentType(int pageIndex = 1, int pageSize = 10)
        {
            var list = await _equipmentrepository.GetListAsync();
            var result = ObjectMapper.Map<List<EquipmentTypeModel>, List<EquipmentTypeDTO>>(list);
            return result;
        }

        public async Task<int> UpdateEquipmentType(EquipmentTypeDTO equipmentType)
        {
            var list = ObjectMapper.Map<EquipmentTypeDTO, EquipmentTypeModel>(equipmentType);
            var result = await _equipmentrepository.UpdateAsync(list);
            return result == null ? 0 : 1;
        }
    }
}
